<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="demo">

    </div>
    <script>
        window.addEventListener('devicemotion', function (e) {
            demo.innerHTML = `
            <div>${e.acceleration.x}</div>
            <div>${e.acceleration.y}</div>
            <div>${e.acceleration.z}</div>
            `
            if(e.acceleration.z){
                if(Math.abs(e.acceleration.z) > 9){
                    alert('上下摇晃')
                }
            }
        })
    </script>
</body>

</html>